package com.future.controller;

import javax.validation.constraints.NotNull;

import com.future.common.annotation.ControllerMapping;
import com.future.common.base.BaseController;
import com.future.dao.BabyStateDao;
import com.future.model.Babystate;
import com.future.requestbean.BabyState;
import com.future.requestbean.BabyStateUpdate;
import com.jfinal.aop.Before;
import com.jfinal.aop.Inject;
import com.jfinal.plugin.activerecord.tx.Tx;

@ControllerMapping("/babystate")
public class BabyStateController extends BaseController {
	@Inject
	private BabyStateDao babyStateDao;

	@Before(Tx.class)
	public void addBabyState() {
		Babystate babystate = getJsonBodyToModel(BabyState.class, Babystate.class);
		this.babyStateDao.save(babystate);
		renderSuccess();
	}

	@Before(Tx.class)
	public void deleteBabyState(@NotNull(message = "选择删除的状态") Long babystateid) {
		this.babyStateDao.deleteById(babystateid);
		renderSuccess();
	}

	@Before(Tx.class)
	public void updateBabystate() {
		Babystate babystate = getJsonBodyToModel(BabyStateUpdate.class, Babystate.class);
		this.babyStateDao.update(babystate);
		renderSuccess();
	}

	public void queryBabyState() {
		renderResult("babystates", this.babyStateDao.queryBabyState());
	}
}
